home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / backup / lnx-bkp-.000 / lnx-bkp- / usr / bin / lbu
Text File  |  1995-02-24  |  40KB  |  1,266 lines

  1. #!/bin/sh
  2. # *************************************************************************
  3. # *                                                                       *
  4. # * Menu-driven backup script using tar. Author Jonathan Warburton-Brown  *
  5. # *                                                                       *
  6. # * This utility is freely distributable under the terms of the GNU GPL.  *
  7. # *                                                                       *
  8. # *************************************************************************
  9. #
  10.  
  11. #
  12. # ------- UNCOMMENT THIS LINE IF YOUR CONSOLE TYPE (eg con80x25) IS NOT
  13. # ------- DEFINED IN THE TERMINFO DATABASE. NOTE MOST USERS OF LINUX USE
  14. # ------- con80x25 SO THIS HAS BEEN INCLUDED WITH THE DISTRIBUTION.
  15. # ------- Also con80x25 makes LBU look much prettier
  16.  
  17. # TERM=vt100 ; export TERM
  18.  
  19. #
  20. # ------- SET THIS VARIABLE TO yes IF ONLY ROOT IS TO BE ALLOWED TO RUN LBU
  21. #
  22.  
  23. lbu_root_only=no
  24.  
  25. #
  26. # ------- CHANGE THIS IF YOU CHANGE THE NAME OF THE BACKUP SCRIPT
  27. #
  28.  
  29. lbu_program_name=lbu
  30.  
  31. #
  32. # ------- CHANGE THIS TO POINT TO THE LBU LIBRARY & HELP FILES
  33. #
  34.  
  35. lbu_dir=/usr/lib/LBU
  36.  
  37. #
  38. # ------- PER USER TEMPORARY STORAGE FILE
  39. #
  40.  
  41. lbu_tmpfile="/tmp/$LOGNAME"lbu_sel
  42.  
  43. # *************************************************************************
  44. # *                        L.B.U Processing sub-routines                  *
  45. # *************************************************************************
  46.  
  47.  
  48. lbu_proceed() {
  49.     lbu_loop1=1
  50.     while [ $lbu_loop1 = 1 ]; do
  51.     dialog --title "$lbu_title" --menu "                      Jonathan Warburton-Brown\n\n                **** MAIN MENU ****" 22 74 11 \
  52.     "Device"   "Select bkup/rstr/cmpr device.   ($lbu_dsply_dev)"     \
  53.     "File/Dir" "Select data to bkup/rstr/cmpr.  ($lbu_dsply_dfl)"     \
  54.     "Options"  "(Un)Set run-time option flags."            \
  55.     "Begin"       "Start the backup procedure."            \
  56.     "Schedule" "Schedule backup/restore for later."            \
  57.     "Restore"  "Restore previous backup."                \
  58.     "Look"     "Look at status screen."                \
  59.     "Compare"  "Check for differences between backup & file-system."\
  60.     "Inspect"  "Look at latest bkup/rstr/cmpr log."            \
  61.     "View"       "View the contents of a previous backup."        \
  62.     "Write"    "Save currently selected details to disk."        \
  63.     "Exclude"  "Create/Modify an exclusion list"            \
  64.     "Help"     "Help regarding the L.B.U."                 \
  65.     "Quit"     "Quit Linux Backup Utility."                2> $lbu_tmpfile
  66.  
  67. # ------- Get selection and act accordingly
  68.  
  69.     if [ $? = 1 -o $? = 255 ]; then
  70.         rm $lbu_tmpfile
  71.         lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  72.         lbu_hgt=5 ; lbu_wth=34
  73.         lbu_message
  74.         reset ; clear
  75.         exit
  76.     fi
  77.  
  78.     lbu_chc=`cat $lbu_tmpfile`
  79.     rm -f $lbu_tmpfile
  80.     case $lbu_chc in
  81.         Device)     lbu_devsel;;
  82.         File/Dir)    lbu_fstsel;;
  83.         Options)    lbu_options;;
  84.         Begin)        lbu_begin;;
  85.         Schedule)    lbu_schedule;;
  86.         Restore)    lbu_restore;;
  87.         Look)        lbu_look;;
  88.         Compare)    lbu_comp;;
  89.         Inspect)    lbu_inspect;;
  90.         View)        lbu_view;;
  91.         Write)             lbu_write;;
  92.         Exclude)    lbu_exclude;;
  93.         Help)
  94.                 lbu_hlpfile="$lbu_dir/lbu_help1"
  95.                 lbu_help
  96.                 ;;
  97.  
  98.         Quit)        lbu_quit;;
  99.         *)        lbu_invent;;
  100.     esac
  101.     done
  102. }
  103.  
  104. # *********************************************************************
  105. # *             Backup device selection subroutine                    * 
  106. # *********************************************************************
  107.  
  108. lbu_devsel() {
  109.     lbu_loop2=1
  110.     lbu_devtype=""
  111.     lbu_dsply_dev=""
  112.     while [ $lbu_loop2 = 1 ]; do
  113.     lbu_devexist=yes
  114.     lbu_ext=$lbu_orig_ext
  115.     lbu_loop2=0
  116.     dialog --title "L.B.U device selection" --inputbox "Select backup/restore device (? for help)" 8 48 2> $lbu_tmpfile
  117.     lbu_device=`tr -s [*\ ] [?_] < $lbu_tmpfile`
  118.     rm -f $lbu_tmpfile
  119.  
  120. # ------- check for no input provided
  121.  
  122.       if [ -z "$lbu_device" ]; then
  123.         lbu_msgtyp="Error" ; lbu_msgtxt="No backup/restore device specified\n        Aborting"
  124.         lbu_hgt=6 ; lbu_wth=38
  125.         lbu_message
  126.         lbu_loop2=0
  127.     else
  128.  
  129. # ------- asking for help ?
  130.  
  131.         if [ $lbu_device = ? ]; then
  132.             lbu_hlpfile="$lbu_dir/lbu_help2"
  133.             lbu_help
  134.             lbu_loop2=1
  135.             lbu_dsply_dev="" ; lbu_device=""
  136.         else
  137.  
  138. # ------- validate that either a block device or a filename is entered
  139.  
  140.             if [ -a $lbu_device ]; then
  141.                 lbu_devtype=`ls -ld $lbu_device | cut -c1`
  142.                 if [ $lbu_devtype = b ]; then
  143.                     lbu_ext=""
  144.                 fi
  145.                 if [ $lbu_devtype = c ]; then
  146.                     lbu_msgtyp="Warning" ; lbu_msgtxt="You have selected a character special\ndevice. Normally such a device is\nselected only if it is a tapedrive\nor similar stream device."
  147.                     lbu_hgt=8 ; lbu_wth=45
  148.                     lbu_message
  149.                     lbu_ext=""
  150.                 fi    
  151.  
  152.                 if [ $lbu_devtype = d ]; then
  153.                     lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a directory.\nPlease specify a file or device."
  154.                     lbu_hgt=6 ; lbu_wth=40
  155.                     lbu_message
  156.                     lbu_loop2=1    
  157.                 fi
  158.  
  159.                 if [ $lbu_devtype = l ]; then
  160.                     lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a link.\nPlease specify a file or device."
  161.                     lbu_hgt=6 ; lbu_wth=40
  162.                     lbu_message
  163.                     lbu_loop2=1    
  164.                 fi
  165.  
  166.             else
  167.                 if [ -a $lbu_device$lbu_ext ]; then
  168.                     lbu_msgtyp="Informational" ; lbu_msgtxt="The file $lbu_device$lbu_ext exists and \nis not a device file. If a BACKUP is being performed\nit will be overwritten. If this is not OK, reselect the device."
  169.                     lbu_hgt=7 ; lbu_wth=70
  170.                     lbu_message
  171.                 else
  172.                     touch $lbu_device$lbu_ext 2> /dev/null
  173.                     rm $lbu_device$lbu_ext 2> /dev/null
  174.                     if [ $? != 0 ]; then
  175.                         lbu_msgtyp="Error" ; lbu_msgtxt="Path to file $lbu_device$lbu_ext not present.\nPlease re-enter."
  176.                         lbu_hgt=6 ; lbu_wth=70
  177.                         lbu_message
  178.                         lbu_loop2=1
  179.                     else
  180.                         lbu_msgtyp="Warning" ; lbu_msgtxt="The file $lbu_device$lbu_ext does NOT exist.\nIf a BACKUP is being performed it will be created as\nan ordinary file.\nIf you are about to perform a RESTORE operation\nit will FAIL unless you specify an existing file or device."
  181.                         lbu_hgt=9 ; lbu_wth=70
  182.                         lbu_message
  183.                         lbu_devexist=no
  184.                     fi
  185.                 fi
  186.             fi
  187.         fi
  188.     fi
  189.  
  190.     if [ ! -z "$lbu_device" ]; then
  191.         lbu_device=$lbu_device$lbu_ext
  192.         lbu_dsply_dev=`echo $lbu_device | cut -c1-20`'...'
  193.     fi
  194.     done
  195. }
  196.  
  197. # ********************************************************************
  198. # *         Backup directory / file selection subroutine             *
  199. # ********************************************************************
  200.  
  201. lbu_fstsel() {
  202.     lbu_loop2=1
  203.     lbu_dirfil=""
  204.     lbu_dsply_dfl=""
  205.     while [ $lbu_loop2 = 1 ]; do
  206.         lbu_loop2=0
  207.         dialog --title "L.B.U directory / file selection" --inputbox "Enter a comma (,) separated list of dirs and/or files (? for help)" 8 77 2> $lbu_tmpfile
  208.         lbu_dirfil=`tr -s "[ ]" "[,]" < $lbu_tmpfile`
  209.         case $lbu_dirfil in
  210.             '')
  211.                 lbu_msgtyp="Warning" ; lbu_msgtxt="No dirs / files specified."
  212.                 lbu_hgt=5 ; lbu_wth=35
  213.                 lbu_message
  214.                 lbu_loop2=0
  215.                 ;;
  216.  
  217.             \*)    ;;
  218.  
  219.             \?)
  220.                 lbu_hlpfile="$lbu_dir/lbu_help3"
  221.                 lbu_help
  222.                 lbu_loop2=1
  223.                 ;;
  224.  
  225.             *)
  226.                 lbu_dirfil=$lbu_dirfil','
  227.                 echo $lbu_dirfil > $lbu_tmpfile
  228.                 lbu_loop3=1
  229.                 lbu_ctr=1
  230.                 while [ $lbu_loop3 = 1 ]; do
  231.                     lbu_field=`cut -f$lbu_ctr -d, < $lbu_tmpfile`
  232.                     case $lbu_field in
  233.                         $lbu_dirfil)    lbu_loop3=0;;
  234.                         *\**)        ;;
  235.                         *\?*)        ;;
  236.                         *)
  237.                         if [ ! -a $lbu_field ]; then
  238.                             lbu_msgtyp="Informational" ; lbu_msgtxt="One of the files or directories specified\ndoes not exist. If doing a BACKUP this will\ncause the Status Screen to show FAILURE\neven though existing files WILL have been\nbacked up. Be sure to check the logfile."
  239.                             lbu_hgt=9 ; lbu_wth=50
  240.                             lbu_message
  241.                             lbu_loop3=0
  242.                         fi;;
  243.                     esac
  244.                 lbu_ctr=`expr $lbu_ctr + 1`
  245.                 done;;
  246.         esac    
  247.     done
  248.     echo $lbu_dirfil > $lbu_tmpfile
  249.     case $lbu_dirfil in
  250.     '')
  251.         rm -f $lbu_tmpfile
  252.         ;;
  253.     *)
  254.         lbu_dirfil=`tr "[,]" "[ ]" <$lbu_tmpfile`
  255.         lbu_dsply_dfl=`echo $lbu_dirfil | cut -c1-20`'...'
  256.         ;;
  257.     esac
  258. }
  259.  
  260. # **********************************************************************
  261. # *                (Un)Set runtime options                             *
  262. # **********************************************************************
  263.     
  264. lbu_options() {
  265.  
  266.     lbu_loop2=1
  267.     while [ $lbu_loop2 = 1 ]; do
  268.         dialog --title "$lbu_title" --menu "\n            **** RUNTIME OPTIONS ****\n" 22 74 14 \
  269.         "Done"     "Return to Main Menu."                    \
  270.         "Multi"    "Multi-volume archive.                  ($lbu_dsply_multi)"     \
  271.         "Absolute" "Preserve absolute pathnames.           ($lbu_dsply_absol)"     \
  272.         "Inform"   "Mail log file to self.                 ($lbu_dsply_mail)"    \
  273.         "Block"       "Specify Block-size.                    ($lbu_dsply_blcks)"    \
  274.         "Perms"       "Preserve permissions.                  ($lbu_dsply_perms)"    \
  275.         "Owner"       "Preserve ownership.                    ($lbu_dsply_owner)"    \
  276.         "Totals"   "Log total byte-count.                  ($lbu_dsply_total)"    \
  277.         "Verbose"  "Verbose logging.                       ($lbu_dsply_vbose)"    \
  278.         "Compress" "Select compression type.               ($lbu_dsply_cmprs)"    \
  279.         "Exclude"  "Enable/Disable file exclusion          ($lbu_dsply_excl)"    \
  280.         "Help"     "Help regarding Options"                    2> $lbu_tmpfile
  281.  
  282. # ------- Get the selection made and act accordingly
  283.  
  284.         if [ $? = 1 -o $? = 255 ]; then
  285.             rm $lbu_tmpfile
  286.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  287.             lbu_hgt=5 ; lbu_wth=34
  288.             lbu_message
  289.             lbu_loop2=0
  290.         else
  291.  
  292.             lbu_sel=`cat $lbu_tmpfile`
  293.             rm -f $lbu_tmpfile
  294.  
  295.             case $lbu_sel in
  296.             Multi)         
  297.                 if [ $lbu_dsply_multi = yes ]; then
  298.                     lbu_dsply_multi=no ; lbu_multi=""
  299.                 else
  300.                     lbu_dsply_multi=yes ; lbu_multi="-M"
  301.                     if [ $lbu_cmprs != "" ]; then
  302.                         lbu_dsply_cmprs="none" ; lbu_cmprs=''
  303.                         lbu_device="" ; lbu_dsply_dev="" ; lbu_orig_ext=".tar"
  304.                         lbu_msgtyp="Informational" ; lbu_msgtxt="Cannot have compressed multi-volume archives.\nCompression parameter set to 'none'.\nYOU MUST RE-SELECT THE BACKUP DEVICE."
  305.                         lbu_hgt=7 ; lbu_wth=55
  306.                         lbu_message
  307.                     fi
  308.                 fi
  309.                 ;;
  310.             Absolute)
  311.                 if [ $lbu_dsply_absol = yes ]; then 
  312.                     lbu_dsply_absol=no  ; lbu_absol=""
  313.                 else
  314.                     lbu_dsply_absol=yes ; lbu_absol="P"
  315.                 fi
  316.                 ;;
  317.             Inform)
  318.                 if [ $lbu_dsply_mail = yes ]; then 
  319.                     lbu_dsply_mail=no  ; lbu_mail=no
  320.                 else
  321.                     lbu_dsply_mail=yes ; lbu_mail=yes
  322.                 fi
  323.                 ;;
  324.             Block)
  325.                 lbu_blocksize
  326.                 ;;
  327.             Perms)    
  328.                 if [ $lbu_dsply_perms = yes ]; then 
  329.                     lbu_dsply_perms=no  ; lbu_perms=""
  330.                 else
  331.                     lbu_dsply_perms=yes ; lbu_perms="p"
  332.                 fi
  333.                 ;;
  334.             Owner)
  335.                 if [ $lbu_dsply_owner = yes ]; then 
  336.                     lbu_dsply_owner=no  ; lbu_owner=""
  337.                 else
  338.                     lbu_dsply_owner=yes ; lbu_owner='--same-owner'
  339.                 fi
  340.                 ;;
  341.             Totals)
  342.                 if [ $lbu_dsply_total = yes ]; then 
  343.                     lbu_dsply_total=no  ; lbu_total=""
  344.                 else
  345.                     lbu_dsply_total=yes ; lbu_total='--totals'
  346.                 fi
  347.                 ;;
  348.             Verbose)
  349.                 if [ $lbu_dsply_vbose = yes ]; then 
  350.                     lbu_dsply_vbose=no  ; lbu_vbose=""
  351.                 else
  352.                     lbu_dsply_vbose=yes ; lbu_vbose="v"
  353.                 fi
  354.                 ;;
  355.             Compress)
  356.                 lbu_compress
  357.                 ;;
  358.             Exclude)
  359.                 if [ $lbu_dsply_excl = yes ]; then 
  360.                     lbu_dsply_excl=no  ; lbu_excl=""
  361.                 else
  362.                     lbu_dsply_excl=yes ; lbu_excl='-X $HOME/.lbu_exclude'
  363.                 fi
  364.                 ;;
  365.             Help)
  366.                 lbu_hlpfile="$lbu_dir/lbu_help4"
  367.                 lbu_help
  368.                 ;;
  369.             Done)
  370.                 lbu_loop2=0
  371.                 ;;
  372.             *)        lbu_invent
  373.                 ;;
  374.             esac
  375.         fi
  376.     done
  377. }
  378.  
  379. # *********************************************************************
  380. # *                   Select Blocksize sub-routine                    *
  381. # *********************************************************************
  382.  
  383. lbu_blocksize() {
  384.         dialog --title "Block-size selection" --menu "" 14 45 7 \
  385.         "5"       "2,560  bytes per block."             \
  386.         "10"       "5,120  bytes per block."             \
  387.         "15"       "7,680  bytes per block."            \
  388.         "20"       "10,240 bytes per block. (default)"        \
  389.         "25"       "12,800 bytes per block."            \
  390.         "30"       "15,360 bytes per block."            \
  391.         "35"       "17,920 bytes per block."            2> $lbu_tmpfile
  392.  
  393. # ------- Get the selection made and act accordingly
  394.  
  395.         if [ $? = 1 -o $? = 255 ]; then
  396.             rm $lbu_tmpfile
  397.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  398.             lbu_hgt=5 ; lbu_wth=34
  399.             lbu_message
  400.         else
  401.             lbu_dsply_blcks=`cat $lbu_tmpfile` ; lbu_blcks=$lbu_dsply_blcks
  402.             rm -f $lbu_tmpfile
  403.         fi
  404. }
  405.  
  406. # ******************************************************************
  407. # *                  Select compression method                     *
  408. # ******************************************************************
  409.  
  410. lbu_compress() {
  411.         dialog --title "Blocksize selection" --menu "** REMEMBER to re-select DEVICE after changing compression mode **" 22 75 6     \
  412.         "gzip"       "Use a gzipped tar archive (default)    (ext = .tgz)"    \
  413.         "compress" "Use a compressed tar archive           (ext =.tar.Z)"     \
  414.         "none"     "Do not use any compression on archive  (ext = .tar)"     2> $lbu_tmpfile
  415.  
  416. # ------- Get the selection made and act accordingly
  417.  
  418.         if [ $? = 1 -o $? = 255 ]; then
  419.             rm $lbu_tmpfile
  420.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  421.             lbu_hgt=5 ; lbu_wth=34
  422.             lbu_message
  423.         else
  424.  
  425.             lbu_dsply_cmprs=`cat $lbu_tmpfile`
  426.             if [ $lbu_dsply_cmprs = gzip ]; then lbu_orig_ext='.tgz'; lbu_cmprs=z ; fi
  427.             if [ $lbu_dsply_cmprs = compress ]; then lbu_orig_ext='.tar.Z' ; lbu_cmprs=Z ; fi
  428.             if [ $lbu_dsply_cmprs = none ]; then lbu_orig_ext='.tar' ; lbu_cmprs='' ;  fi
  429.             rm -f $lbu_tmpfile
  430.             if [ $lbu_dsply_multi = yes ]; then
  431.                 if [ $lbu_cmprs != "" ]; then 
  432.                     lbu_msgtyp="Informational"
  433.                     lbu_msgtxt="Cannot combine compressed format with\na Multi-volume archive. 'Multi' set to 'no'"
  434.                     lbu_hgt=6 ; lbu_wth=60
  435.                     lbu_message
  436.                     lbu_dsply_multi=no ; lbu_multi=""
  437.                 fi
  438.             fi
  439.             lbu_device="" ; lbu_dsply_dev=""
  440.             lbu_msgtyp="Informational" ; lbu_msgtxt="Compression mode changed.\nPLEASE BE SURE TO RE-SELECT DEVICE."
  441.             lbu_hgt=6 ; lbu_wth=40
  442.             lbu_message
  443.         fi
  444. }
  445.  
  446. # ***********************************************************************
  447. # *                       Start the backup process                      *
  448. # ***********************************************************************
  449.  
  450. lbu_begin() {
  451.     if [ -z "$lbu_device" ]; then
  452.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
  453.         lbu_hgt=6 ; lbu_wth=45
  454.         lbu_message
  455.     else
  456.         if [ -z "$lbu_dirfil" ]; then
  457.             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nstarting the Backup"
  458.             lbu_hgt=6 ; lbu_wth=45
  459.             lbu_message
  460.         else
  461.             lbu_cxtd=c
  462.             lbu_buildcmd
  463. # --------- DO THE BACKUP !!!!!
  464.             lbu_status="BACKUP IN PROGRESS"
  465.             echo $lbu_status > $HOME/.lbu_last_backup
  466.             lbu_devexist=yes
  467.             if [ $lbu_dsply_multi = yes ]; then
  468.                 lbu_hlpfile=$lbu_dir/lbu_Minfo
  469.                 lbu_help
  470.                 clear
  471.                 lbu_status=`date`"\n\n========================== BACK-UP IN PROGRESS ============================\n"
  472.                 echo $lbu_status > $HOME/.lbu_last_backup
  473.                 echo "BACKUP STARTED : " `date` > $lbu_logfile
  474.                 eval $lbu_cmd_line | tee -a $lbu_logfile
  475.  
  476.                 if [ $? = 0 ]; then
  477.                     lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: SUCCESS ======================\n"
  478.                 else
  479.                     lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: FAILURE ======================\n"
  480.                 fi
  481.                 echo $lbu_status > $HOME/.lbu_last_backup
  482. #
  483. # ------- If required mail log to user
  484. #
  485.  
  486.                 if [ $lbu_mail = yes ]; then
  487.                     mail -s "L.B.U BACKUP LOG" $LOGNAME < $lbu_logfile
  488.                 fi
  489.  
  490.             else
  491.                 lbu_bkup_rest_comp=BACK-UP
  492.                 lbu_bldsh_bg
  493.                 exec $lbu_bkup_bg &
  494.  
  495.             fi
  496.  
  497.  
  498.         fi
  499.     fi
  500. }
  501.  
  502. # *********************************************************************
  503. # *              Build shellscript for background run                 *
  504. # *********************************************************************
  505.  
  506. lbu_bldsh_bg() {
  507.         echo "#!/bin/sh" > $lbu_bkup_bg
  508.         echo '' >> $lbu_bkup_bg
  509.         echo 'lbu_dir='$lbu_dir >> $lbu_bkup_bg
  510.         echo 'lbu_bkup_rest_comp='$lbu_bkup_rest_comp >> $lbu_bkup_bg
  511.         echo 'home='$HOME >> $lbu_bkup_bg
  512.         echo 'lbu_logfile='$lbu_logfile >> $lbu_bkup_bg
  513.         echo 'lbu_status=`date`"\n\n========================= $lbu_bkup_rest_comp IN PROGRESS ===========================\n"' >> $lbu_bkup_bg
  514.         echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
  515.         echo 'echo $lbu_bkup_rest_comp STARTED : `date` > $lbu_logfile' >> $lbu_bkup_bg
  516.         echo "$lbu_cmd_line >> $lbu_logfile 2>&1" >> $lbu_bkup_bg
  517.         echo 'if [ $? = 0 ]; then' >> $lbu_bkup_bg
  518.         echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: SUCCESS ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
  519.         echo 'else' >> $lbu_bkup_bg
  520.         echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: FAILURE ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
  521.         echo 'fi' >> $lbu_bkup_bg
  522.         echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
  523.         echo '' >> $lbu_bkup_bg
  524.         echo 'lbu_mail='$lbu_mail >> $lbu_bkup_bg
  525.         echo '' >> $lbu_bkup_bg
  526.         echo '#' >> $lbu_bkup_bg
  527.         echo '# ------- If required mail log to user' >> $lbu_bkup_bg
  528.         echo '#' >> $lbu_bkup_bg
  529.         echo '' >> $lbu_bkup_bg
  530.         echo 'if [ $lbu_mail = yes ]; then' >> $lbu_bkup_bg
  531.         echo '    mail -s "L.B.U $lbu_bkup_rest_comp LOG" $LOGNAME < $lbu_logfile' >> $lbu_bkup_bg
  532.         echo 'fi' >> $lbu_bkup_bg
  533.  
  534.         chmod 755 $lbu_bkup_bg
  535. }
  536.  
  537. # *********************************************************************
  538. # *                      Build the command line                       *
  539. # *********************************************************************
  540.  
  541. lbu_buildcmd() {
  542.     lbu_cmd_line="" ; echo $lbu_cmd_line > $lbu_logfile
  543.     lbu_cmd_line='tar '$lbu_multi' '$lbu_total' '$lbu_excl' '$lbu_owner' -b '$lbu_blcks' -'$lbu_cxtd$lbu_absol$lbu_vbose$lbu_perms$lbu_cmprs'f '$lbu_device' '$lbu_dirfil
  544. }
  545.  
  546. # **********************************************************************
  547. # *                         L.B.U Scheduling                           *
  548. # **********************************************************************
  549.  
  550. lbu_schedule() {
  551.  
  552.     case $LOGNAME in
  553.         root)    ;;
  554.         *)    
  555.             lbu_msgtyp="Error" ; lbu_msgtxt="Only the System Manager can set up\nschedules. This function is not\navailable to you."
  556.             lbu_hgt=7 ; lbu_wth=45
  557.             lbu_message
  558.             return
  559.             ;;
  560.     esac        
  561.  
  562.     if [ $lbu_dsply_multi = "yes" ]; then
  563.         lbu_msgtyp="Error" ; lbu_msgtxt="Multi-volume flag is set. Only\nforeground operations allowed."
  564.             lbu_hgt=6 ; lbu_wth=45
  565.             lbu_message
  566.         
  567.      else
  568.         lbu_loop2=1
  569.         while [ $lbu_loop2 = 1 ]; do
  570.         dialog --title "$lbu_title" --menu "\n            **** L.B.U Scheduling ****\n" 22 74 5 \
  571.         "Back"   "Schedule a backup for later."         \
  572.         "Rest"      "Schedule a restore for later."        \
  573.         "Clear"  "Remove a previous schedule."             \
  574.         "Help"    "Help regarding Scheduling"            \
  575.         "Done"    "Return to Main Menu."            2> $lbu_tmpfile
  576.  
  577. # ------- Get selection and act accordingly
  578.  
  579.         if [ $? = 1 -o $? = 255 ]; then
  580.             rm $lbu_tmpfile
  581.             lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
  582.             lbu_hgt=5 ; lbu_wth=34
  583.             lbu_message
  584.             lbu_loop2=0
  585.             return
  586.         fi
  587.  
  588.         lbu_sel=`cat $lbu_tmpfile`
  589.         rm -f $lbu_tmpfile
  590.         case $lbu_sel in
  591.             Back)     
  592.                     if [ -z "$lbu_device" ]; then
  593.                         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Backup"
  594.                         lbu_hgt=6 ; lbu_wth=45
  595.                         lbu_message
  596.                     else
  597.                         if [ -z "$lbu_dirfil" ]; then
  598.                             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nscheduling the Backup"
  599.                             lbu_hgt=6 ; lbu_wth=45
  600.                             lbu_message
  601.                         else
  602.  
  603.                             lbu_cxtd=c
  604.                             lbu_bkup_rest_comp=BACK-UP
  605.                             lbu_schedl
  606.                         fi
  607.                     fi
  608.                     ;;
  609.  
  610.             Rest)    
  611.                     if [ $lbu_devexist = no ]; then
  612.                         lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
  613.                         lbu_hgt=6 ; lbu_wth=45
  614.                         lbu_message
  615.                     else
  616.                         if [ -z "$lbu_device" ]; then
  617.                             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Restore."
  618.                             lbu_hgt=6 ; lbu_wth=45
  619.                             lbu_message
  620.                         else
  621.  
  622.                             lbu_cxtd=x
  623.                             lbu_bkup_rest_comp=RESTORE
  624.                             lbu_schedl
  625.                         fi
  626.                     fi
  627.                     ;;
  628.  
  629.             Clear)        lbu_delsch;;
  630.             Help)        lbu_hlpfile=$lbu_dir/lbu_help5
  631.                     lbu_help
  632.                     ;;
  633.             Done)        lbu_loop2=0
  634.                     ;;
  635.             *)        lbu_invent;;
  636.         esac
  637.         done
  638.     fi
  639. }
  640.  
  641. # **********************************************************************
  642. # *                       Set up a schedule                            *
  643. # **********************************************************************
  644.  
  645. lbu_schedl() {
  646. #
  647. # ------- look for atrun
  648. #
  649.     lbu_cronerr=0
  650.     if [ $LOGNAME = root ]; then
  651.         if [ ! -a /var/spool/cron/crontabs/root ]; then
  652.             lbu_msgtyp="Informational" ; lbu_msgtxt="A crontab file does not exist for $LOGNAME.\nOne will be created."
  653.             lbu_hgt=6 ; lbu_wth=50
  654.             lbu_message
  655.             mkdir /var 2> /dev/null
  656.             mkdir /var/spool 2> /dev/null
  657.             mkdir /var/spool/cron 2> /dev/null
  658.             mkdir /var/spool/cron/crontabs 2> /dev/null
  659.             touch /var/spool/cron/crontabs/$LOGNAME
  660.             if [ $LOGNAME=root ]; then
  661.                 echo "* * * * * * /usr/lib/atrun" >> /var/spool/cron/crontabs/$LOGNAME
  662.             fi
  663.         fi
  664.     fi
  665.     lbu_cdrun=`ps -ax | grep crond | wc -l`
  666.     if [ $lbu_cdrun -lt 2 ]; then
  667.         if [ $LOGNAME = root ]; then
  668.             lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nAttempting to start."
  669.             lbu_hgt=6 ; lbu_wth=45
  670.             lbu_message
  671.             /usr/sbin/crond 2> /dev/null
  672.             if [ $? = 0 ]; then
  673.                 lbu_msgtyp="Status" ; lbu_msgtxt="Crond started."
  674.                 lbu_hgt=5 ; lbu_wth=25
  675.                 lbu_message
  676.             else
  677.                 lbu_msgtyp="Status" ; lbu_msgtxt="Crond FAILED to start.\Please start manually."
  678.                 lbu_hgt=7 ; lbu_wth=35
  679.                 lbu_message
  680.                 lbu_cronerr=1
  681.             fi
  682.         else
  683.             lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nSCHEDULES CANNOT BE RUN.\nPlease contact your system manager."
  684.             lbu_hgt=7 ; lbu_wth=45
  685.             lbu_message
  686.             lbu_cronerr=1
  687.         fi    
  688.     fi
  689.  
  690. #
  691. # ------- get run date build the script to be run by using the at command
  692. #
  693.     if [ $lbu_cronerr = 0 ]; then
  694.         lbu_date
  695.         if [ ! -z "$lbu_date" ]; then
  696.             lbu_buildcmd
  697.             lbu_bldsh_bg
  698.             at -f $lbu_bkup_bg $lbu_hr$lbu_min $lbu_mth$lbu_day$lbu_yr >$lbu_tmpfile 2>&1
  699.             if [ $? = 0 ]; then
  700.                 lbu_jobno=`awk -F\  '{print $2}' < $lbu_tmpfile`
  701.                 lbu_status="SCHEDULED. Job : $lbu_jobno\n\n=========== SCHEDULED $lbu_bkup_rest_comp RUN-TIME IS $lbu_hr:$lbu_min on $lbu_day/$lbu_mth/$lbu_yr ==========="
  702.                 echo $lbu_status > $HOME/.lbu_last_backup
  703.                 lbu_msgtyp="Status" ; lbu_msgtxt="Job has been submitted for execution.\n\nJOB NUMBER IS : $lbu_jobno\n\nPlease make note of this number."
  704.                 lbu_hgt=9 ; lbu_wth=45
  705.                 lbu_message
  706.             else
  707.                 lbu_msgtyp="Status" ; lbu_msgtxt="Job **FAILED** to be submitted."
  708.                 lbu_hgt=5 ; lbu_wth=45
  709.                 lbu_message    
  710.             fi
  711.         fi
  712.     fi
  713. }
  714.  
  715. # **********************************************************************
  716. # *                         Delete a scheduled backup                  *
  717. # **********************************************************************
  718.  
  719. lbu_delsch() {
  720.  
  721.     lbu_loop3=1
  722.     while [ $lbu_loop3 = 1 ]; do
  723.         dialog --title "L.B.U DELETE Schedule" --inputbox "Enter job number (? for help)" 8 40 2> $lbu_tmpfile
  724.         lbu_jobno=`cat $lbu_tmpfile`
  725.         rm -f $lbu_tmpfile
  726.  
  727. # ------- check for no input provided
  728.  
  729.           if [ -z $lbu_jobno ]; then
  730.             lbu_msgtyp="Error" ; lbu_msgtxt="No job number specified\n        Aborting"
  731.             lbu_hgt=6 ; lbu_wth=30
  732.             lbu_message
  733.             lbu_loop3=0
  734.         else
  735.  
  736. # ------- asking for help ?
  737.  
  738.             if [ $lbu_jobno = ? ]; then
  739.                 lbu_hlpfile=$lbu_dir/lbu_help7
  740.                 lbu_help
  741.                 lbu_loop3=1
  742.             else
  743.                 if [ ! -a /var/spool/atjobs/$lbu_jobno ]; then
  744.                     lbu_msgtyp="Error" ; lbu_msgtxt="The specified job number does not exist.\nPlease re-enter."
  745.                     lbu_hgt=6 ;lbu_wth=50
  746.                     lbu_message
  747.                 else
  748.                     lbu_isval=`cat /var/spool/atjobs/$lbu_jobno | grep lbu | wc -l`
  749.                     if [ $lbu_isval = 0 ]; then
  750.                         lbu_msgtyp="Error" ; lbu_msgtxt="This does not appear to be an L.B.U schedule.\nPlease re-enter."
  751.                         lbu_hgt=6 ;lbu_wth=50
  752.                         lbu_message
  753.                      else
  754.                         atrm $lbu_jobno >/dev/null 2>&1
  755.                         lbu_status="SCHEDULE DELETED"
  756.                         echo $lbu_status > $HOME/.lbu_last_backup
  757.                         lbu_msgtyp="Informational" ; lbu_msgtxt="The schedule has been DELETED."
  758.                         lbu_hgt=5 ;lbu_wth=50
  759.                         lbu_message
  760.                         lbu_loop3=0
  761.                     fi
  762.                 fi
  763.             fi
  764.         fi
  765.     done
  766. }
  767.  
  768.  
  769. # **********************************************************************
  770. # *                         L.B.U Restore Backup                       *
  771. # **********************************************************************
  772.  
  773. lbu_restore() {
  774.     if [ $lbu_devexist = no ]; then
  775.          lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
  776.         lbu_hgt=6 ; lbu_wth=45
  777.         lbu_message
  778.     else
  779.         if [ -z "$lbu_device" ]; then
  780.             lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Restore"
  781.             lbu_hgt=6 ; lbu_wth=45
  782.             lbu_message
  783.         else
  784.             if [ -z "$lbu_dirfil" ]; then
  785.                 lbu_msgtyp="Informational" ; lbu_msgtxt="No Dir/File specified. All will be restored."
  786.                 lbu_hgt=5 ; lbu_wth=50
  787.                 lbu_message
  788.             fi
  789.             lbu_cxtd=x
  790.             lbu_buildcmd
  791. # --------- DO THE RESTORE !!!!!
  792.             lbu_status="RESTORE IN PROGRESS"
  793.             echo $lbu_status > $HOME/.lbu_last_backup
  794.             if [ $lbu_dsply_multi = yes ]; then
  795.                 lbu_hlpfile=$lbu_dir/lbu_Minfo
  796.                 lbu_help
  797.                 clear
  798.                 lbu_status=`date`"\n\n====================== RESTORE IN PROGRESS =========================\n"
  799.                 echo $lbu_status > $HOME/.lbu_last_backup
  800.                 echo "RESTORE STARTED : " `date` > $lbu_logfile
  801.                 eval $lbu_cmd_line | tee -a $lbu_logfile
  802.  
  803.                 if [ $? = 0 ]; then
  804.                     lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: SUCCESS ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
  805.                 else
  806.                     lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: FAILURE ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
  807.                 fi
  808.                 echo $lbu_status > $HOME/.lbu_last_backup
  809. #
  810. # ------- If required mail log to user
  811. #
  812.  
  813.                 if [ $lbu_mail = yes ]; then
  814.                     echo DIR = $lbu_dir
  815.                     mail -s "L.B.U RESTORE LOG" $LOGNAME < $lbu_logfile
  816.                 fi
  817.  
  818.             else
  819.                 lbu_bkup_rest_comp=RESTORE
  820.                 lbu_bldsh_bg
  821.                 exec $lbu_bkup_bg &
  822.  
  823.             fi
  824.         fi
  825.     fi
  826. }
  827.  
  828.  
  829.  
  830. # **********************************************************************
  831. # *                          Show STATUS message                       *
  832. # **********************************************************************
  833.  
  834. lbu_look() {
  835.     if [ -f $HOME/.lbu_last_backup ]; then
  836.         lbu_lbu="$lbu_line\nLast L.B.U action / date                   : `cat $HOME/.lbu_last_backup`\n$lbu_line"
  837.     else
  838.         lbu_lbu="$lbu_line\n           No previous L.B.U backup has been performed\n$lbu_line"
  839.     fi
  840.  
  841.     lbu_pwd="Current directory                  : `pwd`"
  842.     lbu_dat="Current date                     : `date`"
  843.     dialog --title "$lbu_title" --msgbox "$lbu_author\n\n$lbu_line\n$lbu_pwd\n$lbu_dat\n$lbu_lbu" 21 79
  844. }
  845.  
  846. # **********************************************************************
  847. # *               Compare backup with file-system                      *
  848. # **********************************************************************
  849.  
  850. lbu_comp() {
  851.     if [ $lbu_devexist = no ]; then
  852.         lbu_msgtyp="Error" ; lbu_msgtxt="The compare device is not valid.\nPlease re-enter."
  853.         lbu_hgt=6 ; lbu_wth=45
  854.         lbu_message
  855.         return
  856.     fi
  857.  
  858.     if [ -z "$lbu_device" ]; then
  859.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
  860.         lbu_hgt=6 ; lbu_wth=45
  861.         lbu_message
  862.     else
  863.         lbu_vbose_orig=$lbu_vbose
  864.         lbu_vbose='v'
  865.         lbu_cxtd=d
  866.         lbu_buildcmd
  867.         lbu_vbose=$lbu_vbose_orig
  868. # --------- DO THE COMPARE
  869.         lbu_status="COMPARE IN PROGRESS"
  870.         echo $lbu_status > $HOME/.lbu_last_backup
  871.         if [ $lbu_dsply_multi = yes ]; then
  872.             lbu_hlpfile=$lbu_dir/lbu_Cinfo
  873.             lbu_help
  874.             clear
  875.             lbu_status=`date`"\n\n======================= COMPARE IN PROGRESS =========================\n"
  876.             echo $lbu_status > $HOME/.lbu_last_backup
  877.             echo "COMPARE STARTED: " `date` > $lbu_logfile
  878.             eval $lbu_cmd_line | tee -a $lbu_logfile
  879.  
  880.             if [ $? = 0 ]; then
  881.                 lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: SUCCESS =====================\n"
  882.             else
  883.                 lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: FAILURE =====================\n"
  884.             fi
  885.             echo $lbu_status > $HOME/.lbu_last_backup
  886. #
  887. # ------- If required mail log to user
  888. #
  889.             if [ $lbu_mail = yes ]; then
  890.                 mail -s "L.B.U COMPARE LOG" $LOGNAME < $lbu_logfile
  891.             fi
  892.  
  893.         else
  894.             lbu_bkup_rest_comp=COMPARE
  895.             lbu_bldsh_bg
  896.             exec $lbu_bkup_bg &
  897.         fi
  898.  
  899.     fi
  900. }
  901.  
  902. # **********************************************************************
  903. # *              Backup log file inspection subroutine                 *
  904. # **********************************************************************
  905.  
  906. lbu_inspect() {
  907.     if [ ! -a $lbu_logfile ]; then
  908.         lbu_msgtyp="Error" ; lbu_msgtxt="There is no log file to view."
  909.         lbu_hgt=5 ; lbu_wth=40
  910.         lbu_message
  911.     else
  912.         dialog --title "Linux Backup Log Inspection" --textbox $lbu_logfile 21 77
  913.     fi
  914.     return 0
  915. }
  916.  
  917. # **********************************************************************
  918. # *               Backup file view subroutine                          *
  919. # **********************************************************************
  920.  
  921. lbu_view() {
  922.     if [ -z "$lbu_device" ]; then
  923.         lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nattempting a view operation"
  924.         lbu_hgt=6 ; lbu_wth=45
  925.         lbu_message
  926.     else
  927.         if [ $lbu_devexist = no ]; then
  928.             lbu_msgtyp="Error" ; lbu_msgtxt="The view device is not valid.\nPlease re-enter."
  929.             lbu_hgt=6 ; lbu_wth=45
  930.             lbu_message
  931.         else
  932.             lbu_cxtd=t
  933.             lbu_excl_orig=$lbu_excl
  934.             lbu_excl=''
  935.             lbu_buildcmd
  936.             lbu_excl=$lbu_excl_orig
  937.             clear
  938.             eval $lbu_cmd_line | more
  939.             echo ''
  940.             echo ''
  941.             echo "======================== Please press RETURN to continue ==================="
  942.             read lbu_null
  943.         fi
  944.     fi
  945. }
  946.  
  947. # **********************************************************************
  948. # *                      L.B.U Save Config Subroutine                  *
  949. # **********************************************************************
  950.  
  951. lbu_write() {
  952.     if [ -f $HOME/.lburc ]; then
  953.         rm $HOME/.lburc
  954.     fi
  955.  
  956.     lbu_quote='"'
  957.     echo "lbu_devtype=$lbu_quote"$lbu_devtype$lbu_quote > $HOME/.lburc
  958.     echo "lbu_dsply_dev=$lbu_quote"$lbu_dsply_dev$lbu_quote >>$HOME/.lburc
  959.     echo "lbu_ext=$lbu_quote"$lbu_ext$lbu_quote >>$HOME/.lburc
  960.     echo "lbu_orig_ext=$lbu_quote"$lbu_orig_ext$lbu_quote >>$HOME/.lburc
  961.     echo "lbu_device="$lbu_quote$lbu_device$lbu_quote >>$HOME/.lburc
  962.  
  963.     echo "lbu_dirfil="$lbu_quote$lbu_dirfil$lbu_quote >>$HOME/.lburc
  964.     echo "lbu_dsply_dfl="$lbu_quote$lbu_dsply_dfl$lbu_quote >>$HOME/.lburc
  965.     echo "lbu_multi="$lbu_quote$lbu_multi$lbu_quote >>$HOME/.lburc
  966.     echo "lbu_dsply_multi="$lbu_quote$lbu_dsply_multi$lbu_quote >>$HOME/.lburc
  967.     echo "lbu_absol="$lbu_quote$lbu_absol$lbu_quote >>$HOME/.lburc
  968.     echo "lbu_dsply_absol="$lbu_quote$lbu_dsply_absol$lbu_quote >>$HOME/.lburc
  969.     echo "lbu_mail="$lbu_quote$lbu_mail$lbu_quote >>$HOME/.lburc
  970.     echo "lbu_dsply_mail="$lbu_quote$lbu_dsply_mail$lbu_quote >>$HOME/.lburc
  971.     echo "lbu_blcks="$lbu_quote$lbu_blcks$lbu_quote >>$HOME/.lburc
  972.     echo "lbu_dsply_blcks="$lbu_quote$lbu_dsply_blcks$lbu_quote >>$HOME/.lburc
  973.     echo "lbu_perms="$lbu_quote$lbu_perms$lbu_quote >>$HOME/.lburc
  974.     echo "lbu_dsply_perms="$lbu_quote$lbu_dsply_perms$lbu_quote >>$HOME/.lburc
  975.     echo "lbu_owner="$lbu_quote$lbu_owner$lbu_quote >>$HOME/.lburc
  976.     echo "lbu_dsply_owner="$lbu_quote$lbu_dsply_owner$lbu_quote >>$HOME/.lburc
  977.     echo "lbu_total="$lbu_quote$lbu_total$lbu_quote >>$HOME/.lburc
  978.     echo "lbu_dsply_total="$lbu_quote$lbu_dsply_total$lbu_quote >>$HOME/.lburc
  979.     echo "lbu_vbose="$lbu_quote$lbu_vbose$lbu_quote >>$HOME/.lburc
  980.     echo "lbu_dsply_vbose="$lbu_quote$lbu_dsply_vbose$lbu_quote >>$HOME/.lburc
  981.     echo "lbu_cmprs="$lbu_quote$lbu_cmprs$lbu_quote >>$HOME/.lburc
  982.     echo "lbu_dsply_cmprs="$lbu_quote$lbu_dsply_cmprs$lbu_quote >>$HOME/.lburc
  983.     echo "lbu_excl="$lbu_quote$lbu_excl$lbu_quote >>$HOME/.lburc
  984.     echo "lbu_dsply_excl="$lbu_quote$lbu_dsply_excl$lbu_quote >>$HOME/.lburc
  985.     echo "==END==" >>$HOME/.lburc
  986.  
  987.     dialog --title "L.B.U Write config" --msgbox "Current configuration saved to\n$HOME.lburc" 6 35
  988. }
  989.  
  990. # **********************************************************************
  991. # *                    L.B.U Exclusion list subroutine                 *
  992. # **********************************************************************
  993.  
  994. lbu_exclude() {
  995.     lbu_hlpfile="$lbu_dir/lbu_help8"
  996.     lbu_help
  997.     lbu_editor=$EDITOR
  998.     if [ -z $lbu_editor ]; then
  999.         vi $HOME/.lbu_exclude
  1000.     else
  1001.         $lbu_editor $HOME/.lbu_exclude
  1002.     fi
  1003. }
  1004.         
  1005. # **********************************************************************
  1006. # *                    L.B.U Quit subroutine                           *
  1007. # **********************************************************************
  1008.  
  1009. lbu_quit() {
  1010.     dialog --title "L.B.U Quit Backup" --msgbox "Quitting L.B.U" 5 25
  1011.     lbu_loop1=0
  1012.     return 0
  1013. }
  1014.  
  1015. # ***********************************************************************
  1016. # *  Invalid Entry subroutine alias 'Bummer I missed THAT possibility'  *
  1017. # ***********************************************************************
  1018.  
  1019. lbu_invent() {
  1020.     dialog --title "L.B.U inv_ent subroutine" --msgbox "Invalid Entry" 5 25
  1021.     return 0
  1022. }
  1023.  
  1024. # ************************************************************************
  1025. # *                Generlised L.B.U utility subroutines                  *
  1026. # ************************************************************************
  1027.  
  1028. #
  1029. # ------- General help display sub-routine
  1030. #
  1031.  
  1032. lbu_help() {
  1033.     dialog --title "Linux Backup Utility Help Screen" --textbox "$lbu_hlpfile" 21 77
  1034. }
  1035.  
  1036. # ------- General error message sub-routine
  1037.  
  1038. lbu_message() {
  1039.     dialog --title "L.B.U $lbu_msgtyp message" --msgbox "$lbu_msgtxt" $lbu_hgt $lbu_wth
  1040.     return 0
  1041. }
  1042.  
  1043. # **********************************************************************
  1044. # *               L.B.U Date entry/validation sub-routine              *
  1045. # **********************************************************************
  1046.  
  1047. lbu_date() {
  1048.     lbu_curdate
  1049.     lbu_loop3=1
  1050.     while [ $lbu_loop3 = 1 ]; do
  1051.         lbu_dterr=1
  1052.     dialog --title "L.B.U Time/Date" --inputbox "Example:\nHH:MM DD Mn YYYY\n15:18 23 02 1995" 10 25 2>$lbu_tmpfile
  1053.     
  1054.         lbu_date=`cat $lbu_tmpfile`
  1055.     
  1056. # ------- check for no input provided
  1057.  
  1058.           if [ -z "$lbu_date" ]; then
  1059.             lbu_msgtyp="Error" ; lbu_msgtxt="No date has been specified\n        Aborting"
  1060.             lbu_hgt=6 ; lbu_wth=35
  1061.             lbu_message
  1062.             lbu_loop3=0
  1063.         else
  1064. #
  1065. # ------- asking for help ?
  1066. #
  1067.             if [ "$lbu_date" = "?" ]; then
  1068.                 lbu_hlpfile=$lbu_dir/lbu_help6
  1069.                 lbu_help
  1070.                 lbu_loop3=1
  1071.                 lbu_dterr=0
  1072.             else
  1073.                 lbu_ccnt=`echo $lbu_date | wc -c`
  1074.                 if [ $lbu_ccnt != 17 ]; then
  1075.                     lbu_msgtyp="Error" ; lbu_msgtxt="The date entered is invalid.\nPlease see the example or\nenter ? for help."
  1076.                     lbu_hgt=7 ; lbu_wth=35
  1077.                     lbu_message
  1078.                 else
  1079.                     lbu_hr=`echo $lbu_date  | cut -c1-2`
  1080.                     lbu_min=`echo $lbu_date | cut -c4-5`
  1081.                     lbu_day=`echo $lbu_date | cut -c7-8`
  1082.                     lbu_mth=`echo $lbu_date | cut -c10-11`
  1083.                     lbu_yr=`echo $lbu_date  | cut -c13-16`
  1084.                     lbu_now=`date +%Y%m%d%H%M`
  1085.                     lbu_reset=`date +%m%d%H%M%Y`
  1086.                     lbu_dval=$lbu_mth$lbu_day$lbu_hr$lbu_min$lbu_yr
  1087.                     lbu_dent=$lbu_yr$lbu_mth$lbu_day$lbu_hr$lbu_min
  1088.                     if [ $lbu_now -ge $lbu_dent ]; then
  1089.                         lbu_msgtyp="Error" ; lbu_msgtxt="The date/time has already passed.\nPlease re-enter."
  1090.                         lbu_hgt=6 ; lbu_wth=40
  1091.                         lbu_message
  1092.                     else
  1093.                         rm -f $lbu_tmpfile
  1094. #
  1095. # ------- date validation
  1096. #
  1097. # ------- use the date command to perform basic validation
  1098. #
  1099.                         date $lbu_dval >/dev/null 2>$lbu_tmpfile
  1100.                         date $lbu_reset >/dev/null 2>&1
  1101.                         if [ -s $lbu_tmpfile ]; then
  1102.                             lbu_msgtyp="Error" ; lbu_msgtxt="Date validation error. Date entered is invalid.\nPlease re-enter."
  1103.                             lbu_hgt=6 ; lbu_wth=50
  1104.                             lbu_message
  1105.                         else
  1106. #
  1107. # ------- use bc to check if leap year
  1108. #
  1109.                             echo $lbu_yr%4 > $lbu_tmpfile
  1110.                             lbu_lyr=`bc < $lbu_tmpfile`
  1111.                             if [ $lbu_lyr != 0 ]; then
  1112.                                 if [ $lbu_day -gt 28 ]; then
  1113.                                     lbu_msgtyp="Error" ; lbu_msgtxt="Date 1validation error. Date entered is invalid.\nPlease re-enter."
  1114.                                     lbu_hgt=6 ; lbu_wth=50
  1115.                                     lbu_message
  1116.                                 else        
  1117.                                     lbu_dterr=0
  1118.                                     lbu_loop3=0
  1119.                                 fi
  1120.                             else
  1121.                                 lbu_dterr=0
  1122.                                 lbu_loop3=0
  1123.                             fi
  1124.                         fi
  1125.                     fi
  1126.                 fi
  1127.             fi
  1128.         fi
  1129.     done
  1130.  
  1131. rm -f $lbu_tmpfile
  1132.  
  1133. }
  1134.  
  1135. # *************************************************************************
  1136. # *               Display the current date and time                       *
  1137. # *************************************************************************
  1138.  
  1139. lbu_curdate() {
  1140.     lbu_cdat=`date`
  1141.     lbu_msgtyp="Informational" ; lbu_msgtxt="The current date and time is :\n$lbu_cdat"
  1142.             lbu_hgt=6 ; lbu_wth=35
  1143.             lbu_message
  1144. }
  1145.  
  1146. # *************************************************************************
  1147. # *               Main body of the Linux Backup Utility              *
  1148. # *************************************************************************
  1149.  
  1150. lbu_1st_time=`ls -a $HOME | grep .lbu_ | wc -l`
  1151. if [ $lbu_1st_time = 0 ]; then
  1152.     dialog --title "Linux Backup Utility Introduction Screen" --textbox "$lbu_dir/lbu_1stintro" 21 77
  1153. fi
  1154.  
  1155. lbu_line="-------------------------------------------------------------------------"
  1156. lbu_orig_term=$TERM
  1157. lbu_title="Linux Backup Utility v1.10"
  1158. lbu_author="   ( jwb@uvo.dec.com )                           Jonathan Warburton-Brown"
  1159. lbu_orig_ext=".tgz"
  1160. lbu_bkup_bg=$HOME/.lbu_bkup_bg
  1161. lbu_logfile=$HOME/.lbu_backup_log
  1162. lbu_redir=''
  1163. lbu_devexist=yes
  1164. lbu_dsply_multi=no    ; lbu_multi=''
  1165. lbu_dsply_absol=yes     ; lbu_absol='P'
  1166. lbu_dsply_mail=no    ; lbu_mail=no
  1167. lbu_dsply_blcks=20    ; lbu_blcks='20'
  1168. lbu_dsply_perms=yes    ; lbu_perms='p'
  1169. lbu_dsply_owner=yes    ; lbu_owner='--same-owner'
  1170. lbu_dsply_total=yes    ; lbu_total='--totals'
  1171. lbu_dsply_vbose=yes    ; lbu_vbose='v'
  1172. lbu_dsply_cmprs=gzip    ; lbu_cmprs='z'
  1173. lbu_dsply_excl=no    ; lbu_excl=''
  1174. #
  1175. # -------- Look for saved configuration details
  1176. #
  1177.  
  1178. # -------- Root only access ?
  1179.  
  1180. if [ $lbu_root_only = yes ]; then
  1181.     if [ $LOGNAME != root ]; then
  1182.         lbu_msgtyp="Error" ; lbu_msgtxt="\n Sorry but you must be\n 'root' to run backups"
  1183.         lbu_hgt=8 ; lbu_wth=30
  1184.         lbu_message
  1185.         TERM=$lbu_orig_term ; export TERM
  1186.         reset ; clear
  1187.         exit
  1188.     fi
  1189. fi    
  1190.     
  1191.  
  1192. #
  1193. # -------- Is another backup process running ?
  1194. #
  1195.  
  1196. lbu_inprg=`ps -ax | grep lbu | wc -l`
  1197. if [ $lbu_inprg != 3 ]; then
  1198.     lbu_msgtyp="Error" ; lbu_msgtxt="Another backup is running or the\nbackup script is being modified.\nPlease try again later."
  1199.     lbu_hgt=7 ; lbu_wth=40
  1200.     lbu_message
  1201.     reset ; clear
  1202.     exit
  1203. fi
  1204.  
  1205. #
  1206. # ------- if you change the name of LBU then you're on your own to
  1207. # ------- change the logo below !!!  ;-)
  1208. #
  1209.  
  1210. if [ -f $HOME/.lburc ]; then
  1211.  
  1212.     dialog --title "$lbu_title" --infobox "\n\n\n\
  1213.            _/_/              _/_/_/_/_/            _/_/    _/_/ \n\
  1214.           _/_/              _/_/    _/_/          _/_/    _/_/  \n\
  1215.          _/_/              _/_/    _/_/          _/_/    _/_/   \n\
  1216.         _/_/              _/_/_/_/_/            _/_/    _/_/    \n\
  1217.        _/_/              _/_/     _/_/         _/_/    _/_/     \n\
  1218.       _/_/       _/_/   _/_/     _/_/  _/_/   _/_/    _/_/      \n\
  1219.      _/_/_/_/_/  _/_/  _/_/_/_/_/_/    _/_/  _/_/_/_/_/_/       \n\n\
  1220.               ( Jonathan Warburton-Brown @ 1995 )\n\n\
  1221.      The Linux Backup Utility is now restoring its saved\n\
  1222.                      configuration details" 20 70
  1223.  
  1224.     lbu_reccnt=`wc -l < $HOME/.lburc`
  1225.     lbu_pcnt=`expr 100 / $lbu_reccnt`
  1226.     lbu_loop=1
  1227.     lbu_ctr=0
  1228.     while [ $lbu_loop = 1 ]; do
  1229.         lbu_ctr=`expr $lbu_ctr + 1`
  1230.         lbu_var=`cat $HOME/.lburc | head -n $lbu_ctr | tail -n 1`
  1231.         echo -ne `expr $lbu_pcnt \* $lbu_ctr`' %'\\b\\b\\b\\b\\b
  1232.         case $lbu_var in
  1233.             ==END==)    break;;
  1234.             *)        eval $lbu_var;;
  1235.         esac
  1236.     done
  1237.     loop=0
  1238.     echo -n '100 %'
  1239. fi
  1240.  
  1241. if [ -a $lbu_device ]; then
  1242.     lbu_devexist=yes
  1243. else
  1244.     lbu_devexist=no
  1245. fi
  1246.  
  1247. #
  1248. # ------- What is the latest status message ?
  1249. #
  1250.  
  1251. lbu_look
  1252.  
  1253. lbu_proceed
  1254. reset ; clear
  1255. exit
  1256.  
  1257. # ***********************************************************************
  1258. # *                         That's all Folks                            *
  1259. # ***********************************************************************
  1260.